package com.soup.dao;

import com.soup.domain.BorrowLog;
import com.soup.utils.JdbcTemplate;

import java.sql.SQLException;
import java.util.List;

public class BorrowLogDao {


    private JdbcTemplate jdbcTemplate;
    public BorrowLogDao(){
        jdbcTemplate = JdbcTemplate.getJdbcTemplate();
    }


    public int order(BorrowLog order){
        String sql = "insert into borrowlog values(?,?,?)";
        try {
            return jdbcTemplate.modify(sql,order.getId(),
                    order.getName(),
                    order.getDat());
        } catch (SQLException e) {
            return -1;
        }
    }

    public int delete(BorrowLog order){
        String sql = "delete from borrowlog where id=? and name=?";
        try {
            return jdbcTemplate.modify(sql,order.getId(),
                    order.getName());
        } catch (SQLException e) {
            return -1;
        }
    }

    public List<BorrowLog> queryOrder(String id){
        String sql = "select * from borrowlog where id = ?";
        List<BorrowLog> query = null;
        try {
            query = jdbcTemplate.query(sql, BorrowLog.class,id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
}
